package cn.base.web.auth.token;

import cn.rengy.auth.AuthenToken;
import cn.rengy.auth.exception.AuthException;
import cn.rengy.auth.token.AuthenTokenCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AuthenTokenManager {

    @Autowired
    private List<AuthenTokenCreator> authenTokenCreators;

    public AuthenToken getAuthenticationToken(Object request) {
        for (AuthenTokenCreator authenTokenCreator : authenTokenCreators) {
            if(authenTokenCreator.supports(request)){
                return authenTokenCreator.getAuthenticationToken(request);
            }
        }
        throw new AuthException(401,"没有匹配的AuthenTokenCreator");
    }
}
